#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
import RandomUtils
import StateTransition
from Enums import EStateElementType
from State import State

import state_transition_test_utils
from base.Sequence import Sequence
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU


#  This test verifies that the default privilege level StateTransitionHandler
#  alters the privilege level State as expected.
class MainSequence(Sequence):
    def __init__(self, aGenThread, aName=None):
        super().__init__(aGenThread, aName)

        self._mExpectedStateData = {}

    def generate(self, **kargs):
        priv_level_names = ("U", "S", None, "M")
        for priv_level in (1, 0, 1, 3):
            state = State()

            if RandomUtils.random32(0, 1) == 1:
                state.addPrivilegeLevelStateElementByName(priv_level_names[priv_level])
            else:
                state.addPrivilegeLevelStateElement(priv_level)

            self._mExpectedStateData[EStateElementType.PrivilegeLevel] = priv_level

            StateTransition.transitionToState(state)
            for _ in range(10):
                self.genInstruction("ADDI##CALM")

            state_transition_test_utils.verify_state(self, self._mExpectedStateData)


MainSequenceClass = MainSequence
GenThreadClass = GenThreadGPGPU
EnvClass = EnvGPGPU
